﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T17_Collection
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 关联性泛型集合(k-v)

            #region Dictionary(哈希表）
            Dictionary<string, Product> dictProducts = new Dictionary<string, Product>();
            dictProducts.Add("t1", new Product());
            dictProducts.Add("t3", new Product());
            dictProducts.Add("t2", new Product());
            //有效数据的个数
            Console.WriteLine(dictProducts.Count);
            //获取值
            Product product;
            Console.WriteLine(dictProducts.TryGetValue("t1",out product));
            //获取键
            foreach(var key in dictProducts.Keys)
            {
                Console.Write("{0}\t",key);
            }
            Console.WriteLine();
            #endregion

            #region SortedDictionary(二叉树)
            SortedDictionary<string, Product> sDictProducts = new SortedDictionary<string, Product>();
            sDictProducts.Add("t1", new Product());
            sDictProducts.Add("t3", new Product());
            sDictProducts.Add("t2", new Product());
            sDictProducts.Add("t4", new Product());
            Console.WriteLine(sDictProducts.Count);
            Console.WriteLine(sDictProducts.ContainsKey("t10"));
            foreach(var key in sDictProducts.Keys)
            {
                Console.Write("{0}\t",key);
            }
            Console.WriteLine();
            #endregion

            #region SortedList(数组)
            SortedList<string, Product> sListProducts = new SortedList<string, Product>();
            sListProducts.Add("t1", new Product());
            sListProducts.Add("t3", new Product());
            sListProducts.Add("t2", new Product());
            foreach (var key in sListProducts.Keys)
            {
                Console.Write("{0}\t", key);
            }
            Console.WriteLine();
            Console.WriteLine(sListProducts.ContainsValue(null));
            #endregion
            #endregion

            #region 非关联性泛型集合

            #region List(数组）
            List<Product> lproducts = new List<Product>();
            lproducts.Add(new Product());
            Console.WriteLine(lproducts[0].GetHashCode());
            #endregion

            #region LinkedList(双向链表）
            LinkedList<Product> llProducts = new LinkedList<Product>();
            llProducts.AddLast(new Product("aa","类型"));
            llProducts.AddFirst(new Product("bb", "类型"));
            foreach (var pro in llProducts)
            {
                Console.Write("{0}\t", pro.Name);
            }
            Console.WriteLine();
            #endregion

            #region HeshSet(哈希表）
            HashSet<Product> hsProducts = new HashSet<Product>();
            hsProducts.Add(new Product("cc", "类型"));
            hsProducts.Add(new Product("aa", "类型"));
            hsProducts.Add(new Product("aa", "类型"));
            hsProducts.Add(new Product("bb", "类型"));
            foreach(var pro in hsProducts)
            {
                Console.Write("{0}\t", pro.Name);
            }
            Console.WriteLine();
            #endregion

            #region SortedSet(二叉树)
            SortedSet<Product> ssProduct = new SortedSet<Product>();
            ssProduct.Add(new Product("cc", "类型"));
            ssProduct.Add(new Product("aa", "类型"));
            ssProduct.Add(new Product("bb", "类型"));
            foreach (var pro in ssProduct)
            {
                Console.Write("{0}\t", pro.Name);
            }
            Console.WriteLine();
            #endregion

            #region Stack(栈)
            Stack<Product> sProduct = new Stack<Product>();
            sProduct.Push(new Product("cccc", "类型"));
            sProduct.Push (new Product("aaaa", "类型"));
            sProduct.Push (new Product("bbbb", "类型"));
            Console.WriteLine(sProduct.Peek().Name );
            Console.WriteLine(sProduct.Pop().Name);
            Console.WriteLine(sProduct.Peek().Name);
            #endregion

            #region Queue(队列)
            Queue<Product> qProduct = new Queue<Product>();
            qProduct.Enqueue(new Product("ccc", "类型"));
            qProduct.Enqueue(new Product("aaa", "类型"));
            qProduct.Enqueue(new Product("bbb", "类型"));
            Console.WriteLine(qProduct.Peek().Name);
            Console.WriteLine(qProduct.Dequeue().Name);
            Console.WriteLine(qProduct.Peek().Name);
            #endregion

            #endregion
            Console.ReadKey();
        }
    }
}
